#ifndef TASK_DB_SYNC_HEADER
#define TASK_DB_SYNC_HEADER

#include "NonCopyable.hpp"
#include <atlbase.h>
#include <atlapp.h>
#include <atlctrls.h>
#include <atlcomtime.h>
#include <map>
#include <atlmisc.h>
#include "sql_util.h"

typedef struct{
	WTL::CString url, local, category;
	int id;
} Task;

template<size_t size> struct variant_ptr_t {
	void *param[size];
};

struct tree_data_t {

	TCHAR text[64];
	UINT count;

	tree_data_t()
	{
		text[0] = '\0';
		count = 0;
	}

	tree_data_t(LPCSTR str, UINT n)
	{
		memset(text, 0, sizeof(text));
		lstrcpyn(text, str, 63);
		count = n;
	}
};

class TaskUtil : public NonCopyable {

    static bool schedule_date_reached(COleDateTime &d, int seconds);

	static int select_task(SQLutil &, const char *sql, std::vector<Task> &tasks);

public:

	static void load_task_tree(SQLutil &, 
		CTreeViewCtrl &tree, 
		std::map<string, HTREEITEM> &category_tree_map);

	static void load_done_task(SQLutil &, CListViewCtrl &, LPCTSTR category);

	static void load_pending_task(SQLutil &, CListViewCtrl &);

    static void load_failed_task(SQLutil &, CListViewCtrl &);

	static int resume_paused_task(SQLutil &, HWND hwnd);

    static int select_sched_task(SQLutil &, std::vector<Task> &tasks);

    static int select_ready_task(SQLutil &, std::vector<Task> &tasks);

    static int select_paused_task(SQLutil &, std::vector<Task> &tasks);

    static int select_retry_task(SQLutil &, std::vector<Task> &tasks);

};

#endif